package com.xyw.his00.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xyw.his00.mapper.DepartmentMapper;
import com.xyw.his00.pojo.dbpojo.Department;
import com.xyw.his00.service.Impl.dbImpl.DepartmentServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/department/")
public class DepartmentController {
   @Autowired
   private DepartmentServiceImpl  departmentServiceImpl;
   @Autowired
   private DepartmentMapper departmentMapper;
    @RequestMapping("getDepartmentById/{id}")
   // @ResponseBody//返回json格式数据，启动类加restcontroller注解，为什么前端响应数据不是json格式？
    //todo:?为什么Integer和String,int都可以？
    public  Department getDepartmentById(@PathVariable int id){
        System.out.println(departmentServiceImpl.getById(id));
        return departmentServiceImpl.getById(id);
    }
   @RequestMapping("getDepartmentsIdAndName")
    public List getDeptments(){
       System.out.println("------获取部门方法执行");
        //部门选择器
       QueryWrapper<Department> queryWrapper = new QueryWrapper<>();
       queryWrapper.select("id", "dept_name"); // 只选择 id 和 name 字段
       List<Department> departments = departmentServiceImpl.list(queryWrapper);
       List<Map<String, Object>> result = departments.stream().map(department -> {
           Map<String, Object> map = new HashMap<>();
           map.put("id", department.getId());
           map.put("deptName", department.getDeptName());
           return map;
       }).toList();
      return result;

   }
   //搜索检查科室
    @GetMapping("selectCheckDeptNameAndId")
    public List<Department>  selectCheckDeptNameAndId(){
        QueryWrapper<Department> queryWrapper=new QueryWrapper<>();
        queryWrapper.like("dept_type","检查");
        return departmentMapper.selectList(queryWrapper);
    }
    //搜索检验科室
    @GetMapping("selectInspectionDeptNameAndId")
    public List<Department>  selectInspectionDeptNameAndId(){
        QueryWrapper<Department> queryWrapper=new QueryWrapper<>();
        queryWrapper.like("dept_type","检验");
        return departmentMapper.selectList(queryWrapper);
    }
    //搜索检验科室
    @GetMapping("selectDisposalDeptNameAndId")
    public List<Department>  selectDisposalDeptNameAndId(){
        QueryWrapper<Department> queryWrapper=new QueryWrapper<>();
        queryWrapper.like("dept_type","处置");
        return departmentMapper.selectList(queryWrapper);
    }
}
